package com.yml.mybatis.gererator;

import com.yml.mybatis.gererator.constant.OrmType;
import com.yml.mybatis.gererator.meta.DataSourceInfo;
import com.yml.mybatis.gererator.service.AutoGenerator;

/**
 * @author YML
 * @since 2024-07-24 16:08
 */
public class Main {
    public static void main(String[] args) throws Exception {
//        executeCode();
//        execute();
        generator("manager-server","com.jhs.manager",
                "HM_CommunicatePlanLog");
    }

    public static void executeCode() throws Exception {
        DataSourceInfo dataSource = new DataSourceInfo(
                "jdbc:mysql://192.168.10.101:3306/lending_dev?allowMultiQueries=true",
                "root",
                "123456");
        dataSource.getConnection();

        // 导出word
//        ExportUtils.exportAllDbInfoToWord(dataSource,"E://Desktop");
        // 导出markdown
//        ExportUtils.exportAllDbInfoToMarkdown(dataSource,"E://Desktop");
        dataSource.close();

    }

    public static void generator(String moduleName,String parentPacket,String... tables) throws Exception {
        DataSourceInfo dataSource = new DataSourceInfo(
                "jdbc:sqlserver://localhost:1433;databaseName=hm_data_dev;encrypt=false",
                "sa",
                "123456");
        AutoGenerator.create(dataSource,
                globalConfig -> globalConfig.setOrmType(OrmType.MYBATIS_PLUS)
                        .setAuthor("YML")
                        .setModulePath(moduleName)
                        .setEnableLombok(true)
                        .setEnableKotlin(false)
                        .setEnableSwagger3(true)
                        .setIgnorePrefix("sys_","dk_","t_","HM_")
                        .setBasePackage(parentPacket)
                ,
                entityConfig -> entityConfig.setEnableGenerateConvert(true).setTables(tables),
                mapperConfig -> mapperConfig.setEnableSelective(true),
                serviceConfig -> {},
                controllerConfig -> {
                }
        ).execute(1);
    }

    public static void execute() throws Exception {
        DataSourceInfo dataSource = new DataSourceInfo(
                "jdbc:mysql://192.168.10.101:3306/lending_dev?allowMultiQueries=true",
                "root",
                "123456");
        var map = AutoGenerator.create(dataSource,
                globalConfig -> {
                    globalConfig.setBasePackage("com.yml.test")
                            .setOrmType(OrmType.MYBATIS_PLUS)
                            .setAuthor("YML")
                            .setIgnorePrefix("dk_", "sys_")
                            .setEnableLombok(true)
                            .setEnableSwagger3(true)
                            .setEnableColumnComment(true)
                            .setEnableKotlin(false);
                },
                entityConfig2 -> {
                    entityConfig2.setTables("sys_user")
                            .setEnableGenerateConvert(true);
                },
                mapperConfig2 -> {
                    mapperConfig2.setEnableSelective(true);
                },
                serviceConfig2 -> {

                },
                controllerConfig -> {

                }
                ).execute(2);
        System.out.println(map.get("sys_user").get("entity"));
    }
}
